package savet.gui.dialogos;

import java.util.List;
import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableColumnModel;
import org.openswing.swing.mdi.client.MDIFrame;
import savet.entidades.atributos.Atributo;
import savet.entidades.atributos.Legenda;
import savet.util.ListLegendas;

/**
 *
 * @author Adisson
 */
public class DialogoLegendas extends javax.swing.JDialog
        implements TableModelListener, LegendaListListener {

    private Atributo atributo;
    private ListLegendas listLegendas = ListLegendas.getInstance();
    private Class atributoRelacionado;

    /** Creates new form DialogoEmentas */
    public DialogoLegendas(java.awt.Frame parent, boolean modal, Atributo atributo, Class atributoRelacionado) {
        super(parent, modal);
        this.atributo = atributo;
        this.atributoRelacionado = atributoRelacionado;
        initComponents();

        configurarJTables();
//        carregarLegendasDefault();
        carregarLegendas();

    }

    /**
     * Configura CellRenderer contendo JCheckBox e um MouseAdapter para
     * editar o estado dos checkboxes
     */
    private void configurarJTables() {
        TableColumnModel cmAutuacao = tableAutuacao.getColumnModel();
        TableColumnModel cmOrientacao = tableOrientacao.getColumnModel();

        cmAutuacao.getColumn(0).setMaxWidth(50);
        cmAutuacao.getColumn(0).setCellEditor(new DefaultCellEditor(new JCheckBox()));
        cmAutuacao.getColumn(1).setCellEditor(new LegendaCellEditor());
        cmAutuacao.getColumn(1).setCellRenderer(new LegendaCellRenderer());
        cmOrientacao.getColumn(0).setMaxWidth(50);
        cmOrientacao.getColumn(0).setCellEditor(new DefaultCellEditor(new JCheckBox()));
        cmOrientacao.getColumn(1).setCellEditor(new LegendaCellEditor());
        cmOrientacao.getColumn(1).setCellRenderer(new LegendaCellRenderer());

        modeloAutuacao.addTableModelListener(this);
        modeloOrientacao.addTableModelListener(this);
    }

    private void adicionarLegendaAtributo(Legenda legSelecionada) {
        atributo.getLegendas().add(legSelecionada);
        listLegendas.addLegenda(legSelecionada);
    }

    private void removerLegendaAtributo(Legenda legSelecionada) {
        atributo.getLegendas().remove(legSelecionada);
        listLegendas.addLegenda(legSelecionada);
    }

    private void carregarLegendasDefault() {
        List<Legenda> legendas = atributo.getLegendas();
        Legenda legendaAutuacao = new Legenda("Legenda de teste de autuacao", Legenda.LEGENDA_AUTUACAO);
        Legenda legendaOrientacao = new Legenda("Legenda de teste de orientacao", Legenda.LEGENDA_ORIENTACAO);
//        if (!legendas.contains(legendaAutuacao)) {
        modeloAutuacao.addLegenda(legendaAutuacao);
//        }
//        if (!legendas.contains(legendaOrientacao)) {
        modeloOrientacao.addLegenda(legendaOrientacao);
//        }
    }

    private void carregarLegendas() {
        List<Legenda> legendas = listLegendas.getList();
        int index = -1;
        for (Legenda legenda : legendas) {
            if (legenda.getAtributoRelacionado() == atributoRelacionado) {
                if (legenda.getTipo() == Legenda.LEGENDA_AUTUACAO) {
                    if (atributo.getLegendas().contains(legenda)) {
                        modeloAutuacao.selecionarLegenda(legenda);
                    } else {
                        modeloAutuacao.addLegenda(legenda);
                    }
                } else {
                    if (atributo.getLegendas().contains(legenda)) {
                        modeloOrientacao.selecionarLegenda(legenda);
                    } else {
                        modeloOrientacao.addLegenda(legenda);
                    }
                }
            }
        }
    }

    private void alterarEstadoAtributo() {
        // lista autuacoes selecionadas
        List<Legenda> las = modeloAutuacao.getLegendasSelecionadas();
        // lista orientacoes selecionadas
        List<Legenda> los = modeloOrientacao.getLegendasSelecionadas();
        boolean checkAtuacoes = las.size() > 0;
        boolean checkObservacoes = los.size() > 0;

        if (checkOk.isSelected()) {
            this.atributo.setEstado(Atributo.NOTIFICADO);
        } else if (checkNaoObrigado.isSelected()) {
            this.atributo.setEstado(Atributo.NAO_OBRIGATORIO);
        } else if (checkAtuacoes) {
            this.atributo.setEstado(Atributo.COM_AUTUACAO);
        } else if (checkObservacoes) {
            this.atributo.setEstado(Atributo.COM_ORIENTACAO);
        } else if (checkAtuacoes && checkObservacoes) {
            this.atributo.setEstado(Atributo.COM_AUTUACAO_ORIENTACAO);
        } else {
            this.atributo.setEstado(Atributo.NAO_NOTIFICADO);
        }

        for (Legenda legenda : las) {
            if (!atributo.getLegendas().contains(legenda)) {
                atributo.getLegendas().add(legenda);
                System.out.println("adicionando legenda " + legenda);
            }
        }

        for (Legenda legenda : los) {
            if (!atributo.getLegendas().contains(legenda)) {
                atributo.getLegendas().add(legenda);
                System.out.println("adicionando legenda " + legenda);
            }
        }

//      Logger.getLogger(getClass().getName()).info("Estado do atributo alterado!");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        autuacaoGroup = new javax.swing.ButtonGroup();
        observacaoGroup = new javax.swing.ButtonGroup();
        buttonGroup1 = new javax.swing.ButtonGroup();
        modeloAutuacao = new savet.gui.modelos.LegendaSelectionTableModel();
        modeloOrientacao = new savet.gui.modelos.LegendaSelectionTableModel();
        btnOk = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        painelAutuacao = new javax.swing.JPanel();
        addAutuacao = new javax.swing.JButton();
        removeAutuacao = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableAutuacao = new javax.swing.JTable();
        painelOrientacao = new javax.swing.JPanel();
        removeOrientacao = new javax.swing.JButton();
        addOrientacao = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tableOrientacao = new javax.swing.JTable();
        painelOutros = new javax.swing.JPanel();
        checkOk = new javax.swing.JCheckBox();
        checkNaoObservado = new javax.swing.JCheckBox();
        checkNaoObrigado = new javax.swing.JCheckBox();

        FormListener formListener = new FormListener();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        btnOk.setText("OK");
        btnOk.addActionListener(formListener);

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(formListener);

        painelAutuacao.setBorder(javax.swing.BorderFactory.createTitledBorder("Legendas de autuação"));

        addAutuacao.setText("+");
        addAutuacao.addActionListener(formListener);

        removeAutuacao.setText("-");
        removeAutuacao.addActionListener(formListener);

        tableAutuacao.setModel(modeloAutuacao);
        tableAutuacao.setColumnSelectionAllowed(true);
        tableAutuacao.setRowHeight(20);
        tableAutuacao.setRowMargin(2);
        jScrollPane1.setViewportView(tableAutuacao);
        tableAutuacao.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tableAutuacao.getColumnModel().getColumn(0).setResizable(false);
        tableAutuacao.getColumnModel().getColumn(0).setHeaderValue("");
        tableAutuacao.getColumnModel().getColumn(1).setHeaderValue("Legendas");

        javax.swing.GroupLayout painelAutuacaoLayout = new javax.swing.GroupLayout(painelAutuacao);
        painelAutuacao.setLayout(painelAutuacaoLayout);
        painelAutuacaoLayout.setHorizontalGroup(
            painelAutuacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelAutuacaoLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 301, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelAutuacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(removeAutuacao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(addAutuacao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        painelAutuacaoLayout.setVerticalGroup(
            painelAutuacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelAutuacaoLayout.createSequentialGroup()
                .addGroup(painelAutuacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelAutuacaoLayout.createSequentialGroup()
                        .addComponent(addAutuacao)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(removeAutuacao))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        painelOrientacao.setBorder(javax.swing.BorderFactory.createTitledBorder("Legendas de orientação"));

        removeOrientacao.setText("-");
        removeOrientacao.addActionListener(formListener);

        addOrientacao.setText("+");
        addOrientacao.addActionListener(formListener);

        tableOrientacao.setModel(modeloOrientacao);
        tableOrientacao.setColumnSelectionAllowed(true);
        tableOrientacao.setRowHeight(20);
        tableOrientacao.setRowMargin(2);
        jScrollPane2.setViewportView(tableOrientacao);
        tableOrientacao.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tableOrientacao.getColumnModel().getColumn(0).setResizable(false);
        tableOrientacao.getColumnModel().getColumn(0).setHeaderValue("");
        tableOrientacao.getColumnModel().getColumn(1).setHeaderValue("Legendas");

        javax.swing.GroupLayout painelOrientacaoLayout = new javax.swing.GroupLayout(painelOrientacao);
        painelOrientacao.setLayout(painelOrientacaoLayout);
        painelOrientacaoLayout.setHorizontalGroup(
            painelOrientacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelOrientacaoLayout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelOrientacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(removeOrientacao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(addOrientacao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(396, 396, 396))
        );
        painelOrientacaoLayout.setVerticalGroup(
            painelOrientacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelOrientacaoLayout.createSequentialGroup()
                .addGroup(painelOrientacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelOrientacaoLayout.createSequentialGroup()
                        .addComponent(addOrientacao)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(removeOrientacao))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        painelOutros.setBorder(javax.swing.BorderFactory.createTitledBorder("Outros"));

        checkOk.setText("Ok (Atributo regular)");

        checkNaoObservado.setSelected(this.atributo.getEstado() == Atributo.NAO_NOTIFICADO || this.atributo.getEstado() == Atributo.NAO_SE_APLICA);
        checkNaoObservado.setText("Não observado");

        checkNaoObrigado.setSelected(this.atributo.getEstado() == Atributo.NAO_OBRIGATORIO);
        checkNaoObrigado.setText("Não obrigatório");

        javax.swing.GroupLayout painelOutrosLayout = new javax.swing.GroupLayout(painelOutros);
        painelOutros.setLayout(painelOutrosLayout);
        painelOutrosLayout.setHorizontalGroup(
            painelOutrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelOutrosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelOutrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(checkOk)
                    .addComponent(checkNaoObservado)
                    .addComponent(checkNaoObrigado))
                .addContainerGap(601, Short.MAX_VALUE))
        );
        painelOutrosLayout.setVerticalGroup(
            painelOutrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelOutrosLayout.createSequentialGroup()
                .addComponent(checkOk)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(checkNaoObservado)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(checkNaoObrigado))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(painelAutuacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(painelOrientacao, javax.swing.GroupLayout.PREFERRED_SIZE, 368, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(painelOutros, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnOk)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancelar)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(painelOutros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(painelAutuacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnOk)
                            .addComponent(btnCancelar)))
                    .addComponent(painelOrientacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }

    // Code for dispatching events from components to event handlers.

    private class FormListener implements java.awt.event.ActionListener {
        FormListener() {}
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == btnOk) {
                DialogoLegendas.this.btnOkActionPerformed(evt);
            }
            else if (evt.getSource() == btnCancelar) {
                DialogoLegendas.this.btnCancelarActionPerformed(evt);
            }
            else if (evt.getSource() == addAutuacao) {
                DialogoLegendas.this.addAutuacaoActionPerformed(evt);
            }
            else if (evt.getSource() == removeAutuacao) {
                DialogoLegendas.this.removeAutuacaoActionPerformed(evt);
            }
            else if (evt.getSource() == removeOrientacao) {
                DialogoLegendas.this.removeOrientacaoActionPerformed(evt);
            }
            else if (evt.getSource() == addOrientacao) {
                DialogoLegendas.this.addOrientacaoActionPerformed(evt);
            }
        }
    }// </editor-fold>//GEN-END:initComponents

    private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
        alterarEstadoAtributo();
        dispose();
    }//GEN-LAST:event_btnOkActionPerformed
    private void addAutuacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addAutuacaoActionPerformed
        criarDialogoSelecaoLegendas();
    }//GEN-LAST:event_addAutuacaoActionPerformed

    private void criarDialogoSelecaoLegendas() {
        System.out.println("criarDialogoSelecaoLegendas");
        DialogoSelecaoLegenda2 dsl = new DialogoSelecaoLegenda2(MDIFrame.getInstance(), true, this,atributoRelacionado);
    }

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
//        atributo.getLegendas().removeAll(legendasAdicionadas);
        dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed
    private void removeAutuacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeAutuacaoActionPerformed
        int indexSelected = tableAutuacao.getSelectedRow();
        Legenda legenda = (Legenda) modeloAutuacao.getValueAt(indexSelected, 1);
        atributo.getLegendas().remove(legenda);
        modeloAutuacao.removeLegenda((Legenda) legenda);
    }//GEN-LAST:event_removeAutuacaoActionPerformed

    private void removeOrientacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeOrientacaoActionPerformed
        int indexSelected = tableOrientacao.getSelectedRow();
        Legenda legenda = (Legenda) modeloOrientacao.getValueAt(indexSelected, 1);
        atributo.getLegendas().remove(legenda);
        modeloOrientacao.removeLegenda((Legenda) legenda);
    }//GEN-LAST:event_removeOrientacaoActionPerformed

    private void addOrientacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addOrientacaoActionPerformed
        criarDialogoSelecaoLegendas();
    }//GEN-LAST:event_addOrientacaoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                DialogoLegendas dialog = new DialogoLegendas(new javax.swing.JFrame(), true, new Atributo(), null);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addAutuacao;
    private javax.swing.JButton addOrientacao;
    private javax.swing.ButtonGroup autuacaoGroup;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnOk;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JCheckBox checkNaoObrigado;
    private javax.swing.JCheckBox checkNaoObservado;
    private javax.swing.JCheckBox checkOk;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private savet.gui.modelos.LegendaSelectionTableModel modeloAutuacao;
    private savet.gui.modelos.LegendaSelectionTableModel modeloOrientacao;
    private javax.swing.ButtonGroup observacaoGroup;
    private javax.swing.JPanel painelAutuacao;
    private javax.swing.JPanel painelOrientacao;
    private javax.swing.JPanel painelOutros;
    private javax.swing.JButton removeAutuacao;
    private javax.swing.JButton removeOrientacao;
    private javax.swing.JTable tableAutuacao;
    private javax.swing.JTable tableOrientacao;
    // End of variables declaration//GEN-END:variables

    public void tableChanged(TableModelEvent e) {

        int row = e.getFirstRow();
        int column = e.getColumn();

        // Verifica se a legenda foi desmarcada em alguns dos modelos.
        // Caso seja verdadeiro, essa legenda sera removida do Atributo
        if (column == 0) {
            if (e.getType() == TableModelEvent.UPDATE) {

                Legenda l;

                // Verificacao para legendas de autuacao
                if (e.getSource() == modeloAutuacao && !modeloAutuacao.isLegendaSelecionada(row)) {
                    l = (Legenda) modeloAutuacao.getValueAt(row, 1);
                    atributo.getLegendas().remove(l);

                    // Verificacao para legendas de orientacao
                } else if (e.getSource() == modeloOrientacao && !modeloOrientacao.isLegendaSelecionada(row)) {
                    l = (Legenda) modeloOrientacao.getValueAt(row, 1);
                    atributo.getLegendas().remove(l);
                }
            }
        }
    }

    public void addLegend(Legenda legenda) {
        System.out.println();
        legenda.setAtributoRelacionado(atributoRelacionado);
        listLegendas.addLegenda(legenda);
        if (legenda.getTipo() == Legenda.LEGENDA_AUTUACAO) {
            modeloAutuacao.addLegenda(legenda);
        } else {
            modeloOrientacao.addLegenda(legenda);
        }
    }

    public void removerLagend(Legenda legenda) {
        if (legenda.getTipo() == Legenda.LEGENDA_AUTUACAO) {
            modeloAutuacao.removeLegenda(legenda);
        } else {
            modeloOrientacao.removeLegenda(legenda);
        }
    }
}
